﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SWSoft.Framework;
using MediSIIM.BizComponent.GuiZhouSXNB;
using GuiZhouSXNB.ServiceReference1;

namespace GuiZhouSXNB
{
    public partial class Form1 : Form
    {
        public static string[] args;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            var xml = "<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"yes\" ?>" +
                "<data>" +
                "<akb020>" + "18808" + "</akb020>" +
                "<ykb003> http://10.168.128.11:9999/assi3wbs/services/HisInterfaceWeb</ykb003>" +
                "<yab003>0401</yab003>" +
                "<sybz>04</sybz>" +
                "</data>";
            var hiwt = new ServiceReference2.HisInterfaceWebPortTypeClient();
            var sr = hiwt.setWebserviceURL(xml);
            //            接口号
            //String astr_jysr_xml, --HIS组织接口输入
            //String astr_jysc_xml, --社保返回接口输出
            //String aint_appcode, --接口返回成功标志
            //String astr_appmsg  --社保错误提示
            sr = hiwt.hisInterfaceCall("01", "<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"yes\" ?>" +
"<data><akb020>100007</akb020>" +
"<ykb003>http://10.168.128.11: 9999/assi3wbs/services/HisInterfaceWeb</ykb003>" +
"<yab003>0401</yab003>" +
"<sybz>04</sybz>" +
"</data>", " ", " ", " ");
            MessageBox.Show(sr);
            var entry = DBVisitor.ExecuteModel("SELECT * FROM yb_ywzcxx yy WHERE yy.czyhgh='DBA' AND yy.yhywzt=1 AND yy.ylbxid=102 and ywxtlb=2");
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;
            comboBox3.SelectedIndex = 0;
        }

        private void textBox1_MouseClick(object sender, MouseEventArgs e)
        {
            textBox1.SelectAll();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var callparam = new GuiZhouSXNBTradeParms(comboBox1.SelectedIndex == 0 ? "traceQueryD" : "traceQueryC");
            callparam[0] = DateTime.Now.Year.ToString(); //	字符	4	不可空	年份
            callparam[1] = "";//	字符	6	不可空	县区编号
            callparam[2] = textBox1.Text; //	字符	20	不可空	住院补偿序号
            callparam.YBCall(callparam);
            var table = new DataTable();
            table.Columns.Add("明细流水号");
            table.Columns.Add("住院补偿号");
            table.Columns.Add("项目编码");
            table.Columns.Add("项目名称");
            table.Columns.Add("项目类别名称");
            table.Columns.Add("单位");
            table.Columns.Add("规格");
            table.Columns.Add("剂型");
            table.Columns.Add("单价");
            table.Columns.Add("数量");
            table.Columns.Add("总价");
            table.Columns.Add("补偿比例");
            table.Columns.Add("保内外");
            table.Columns.Add("用药时间");
            table.Columns.Add("入库时间");
            foreach (var item in callparam.OutData as List<string>[])
            {
                var row = table.NewRow();
                row.ItemArray = item.GetRange(0, 15).ToArray<object>();
                table.Rows.Add(row);
            }
            dataGridView1.DataSource = table;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var callparam = new GuiZhouSXNBTradeParms(comboBox2.SelectedIndex == 0 ? "traceQueryTargetQ" : "traceQueryTargetK");
            callparam[0] = DateTime.Now.Year.ToString(); //	字符	4	不可空	年份
            callparam[1] = "";//	字符	6	不可空	县区编号
            callparam[2] = textBox2.Text; //	字符	20	不可空	住院补偿序号
            callparam.YBCall(callparam);
            var list = new List<string>();
            var table = new DataTable();
            table.Columns.Add("名称");
            table.Columns.Add("数据");
            list.Add("是否成功");
            list.Add("患者姓名");
            list.Add("患者性别");
            list.Add("年龄");
            list.Add("医疗证号");
            list.Add("家庭地址");
            list.Add("联系方式");
            list.Add("就医机构名称");
            list.Add("入院时间");
            list.Add("出院时间");
            list.Add("出院诊断");
            list.Add("住院天数");
            list.Add("本年度住院次数");
            list.Add("住院总费用");
            list.Add("保内费用");
            list.Add("自费费用");
            list.Add("起伏线");
            list.Add("实际补偿");
            list.Add("自付金额");
            list.Add("年度累计补偿");
            list.Add("备注");
            list.Add("计算过程");
            var outdata = callparam.OutData as List<string>;
            for (int i = 0; i < 22; i++)
            {
                var row = table.NewRow();
                row.ItemArray = new object[] { list[i], outdata[i] };
                table.Rows.Add(row);
            }
            dataGridView2.DataSource = table;
        }

        private void textBox2_MouseClick(object sender, MouseEventArgs e)
        {
            textBox2.SelectAll();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            return;
            textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            var sql = string.Format("SELECT ybjyhm,yz.ybbrxx FROM yb_zydjxx yz WHERE yz.ylbxid={0} AND yz.ybjyhm LIKE '%{1}%'", args[0], textBox1.Text);
            var entry = DBVisitor.ExecuteTable(sql);
            foreach (DataRow item in entry.Rows)
            {
                textBox1.AutoCompleteCustomSource.Add(item["ybjyhm"] + item["ybbrxx"].ToString().Split('|')[2]);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            var callparam = new GuiZhouSXNBTradeParms(comboBox3.SelectedIndex == 0 ? "traceQueryE1" : "traceQueryH");
            if (comboBox3.SelectedIndex == 0)
            {
                callparam[0] = DateTime.Now.Year.ToString();//年份
                callparam[1] = "520423";//县区编号
                callparam[2] = "116174";//医疗机构编号
                callparam[3] = "2012-10-17";//统计时间起始（yyyy-mm-dd）
                callparam[4] = "2012-10-18";//统计时间结束（yyyy-mm-dd）
                callparam.YBCall(callparam);
                var table = new DataTable("");
                table.Columns.Add("姓名");
                table.Columns.Add("性别");
                table.Columns.Add("年龄");
                table.Columns.Add("住址");
                table.Columns.Add("医疗证号");
                table.Columns.Add("就诊时间");
                table.Columns.Add("就医机构名称");
                table.Columns.Add("医生");
                table.Columns.Add("补偿时间");
                table.Columns.Add("疾病名称");
                table.Columns.Add("门诊总费用");
                table.Columns.Add("西药费");
                table.Columns.Add("中药费");
                table.Columns.Add("检查费");
                table.Columns.Add("治疗费");
                table.Columns.Add("其他费用");
                table.Columns.Add("补偿门诊药费");
                table.Columns.Add("补偿门诊医疗费");
                table.Columns.Add("实际补偿金额");
                table.Columns.Add("庭账户补偿金额");
                table.Columns.Add("庭统筹补偿金额");
                table.Columns.Add("操作员");
                table.Columns.Add("补偿序号");
                foreach (var item in callparam.OutData as ArrayOfString[])
                {
                    var row = table.NewRow();
                    row.ItemArray = item.ToArray();
                    table.Rows.Add(row);
                }
                if (textBox3.Text != "")
                {

                    var dv = table.DefaultView;
                    dv.RowFilter = "医疗证号='" + textBox3.Text + "'";
                    table = dv.ToTable();
                }

                dataGridView3.DataSource = table;
            }
            else
            {
                callparam[0] = textBox3.Text;//医疗证号
                callparam.YBCall(callparam);
                var table = new DataTable();
                table.Columns.Add("补偿序号");
                table.Columns.Add("患者姓名");
                table.Columns.Add("患者性别");
                table.Columns.Add("医疗证号");
                table.Columns.Add("住院号");
                table.Columns.Add("入院时间");
                table.Columns.Add("出院时间");
                table.Columns.Add("就医机构名");
                table.Columns.Add("出院诊断");
                table.Columns.Add("住院总费用");
                table.Columns.Add("保内费用");
                table.Columns.Add("补偿费用");
                table.Columns.Add("补偿机构");
                table.Columns.Add("操作员");
                table.Columns.Add("业务状态");
                table.Columns.Add("补偿时间");
                table.Columns.Add("未知");
                foreach (var item in callparam.OutData as ArrayOfString[])
                {
                    var row = table.NewRow();
                    row.ItemArray = item.ToArray();
                    table.Rows.Add(row);
                }
                dataGridView3.DataSource = table;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            var callparam = new GuiZhouSXNBTradeParms("traceQueryTargetJ");
            callparam[0] = DateTime.Now.Year.ToString();//            年份
            callparam[1] = "520423";// 地区编号
            callparam[2] = textBox4.Text;// 住院主记录序号
            callparam.YBCall(callparam);
            MessageBox.Show(callparam.OutData.ToString());
        }

        private void addrowno(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            try
            {
                //添加行号 
                SolidBrush v_SolidBrush = new SolidBrush((sender as DataGridView).RowHeadersDefaultCellStyle.ForeColor);
                int v_LineNo = 0;
                v_LineNo = e.RowIndex + 1;

                string v_Line = v_LineNo.ToString();

                e.Graphics.DrawString(v_Line, e.InheritedRowStyle.Font, v_SolidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);

            }
            catch (Exception ex)
            {
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            var callparam = new GuiZhouSXNBTradeParms("traceQueryTargetN");
            callparam[0] = DateTime.Now.Year.ToString();//年份
            callparam[1] = "520423";//地区编号
            callparam[2] = textBox4.Text;//门诊主记录序号
            callparam[3] = true;//是否删除主记录
            callparam.YBCall(callparam);
            MessageBox.Show(callparam.OutData.ToString());
        }

        private void button6_Click(object sender, EventArgs e)
        {
            var callparam = new GuiZhouSXNBTradeParms("traceQueryTargetR");//门诊冲红
            callparam[0] = System.DateTime.Now.Year.ToString();//年份
            callparam[1] = "520423";                    //地区编号
            callparam[2] = textBox4.Text;                       //门诊主记录序号
            callparam.YBCall(callparam);
            var str = "";
            foreach (var item in callparam.OutData as ArrayOfString)
            {
                str += item + "|";
            }
            MessageBox.Show(str);
        }
    }
}